//
//  M4LoanResultCell.swift
//  M4
//
//  Created by YuChuang on 2024/8/20.
//

import UIKit

enum M4LoanResultAction: Int {
    case M4ResultPrivacyAction = 0
    case M4RecommendProAction = 1
    case M4ResultReturnHome = 2
}

class M4LoanResultCell: M4BaseTableViewCell {
    
    @IBOutlet weak var M4LoanResultLogo: UIImageView!
    
    @IBOutlet weak var M4LoanResultName: UILabel!
    
    @IBOutlet weak var M4LoanResultImage: UIImageView!
    
    @IBOutlet weak var M4LoanResultSataus: UILabel!
    
    @IBOutlet weak var M4LoanResultDescribe: UILabel!
    
    @IBOutlet weak var M4LoanResultAmount: UILabel!
    
    @IBOutlet weak var M4LoanResultDays: UILabel!
    
    @IBOutlet weak var M4LoanPrivacyButton: UIButton!
    
    @IBOutlet weak var M4LoanPrivacyButtonHeight: NSLayoutConstraint!
    
    @IBOutlet weak var M4LoanResultLabel: UILabel!
    
    @IBOutlet weak var M4DecriptionView: M4DecriptionStringView!
    
    override func awakeFromNib() {
        super.awakeFromNib()
        let autid = M4UserDataManager.m4UserShare.M4AuditAccount
        M4LoanPrivacyButton.isHidden = autid == 1 ? false : true
        M4LoanPrivacyButtonHeight.constant = autid == 1 ? 20 : 0
    }
    
    override func M4UpdateDataAndUI() {
        guard let model = data as? M4LoanResultModel else {return}
        guard model.QKDLhYTHobF?.count ?? 0 > 0 else {return}
        guard let order = model.QKDLhYTHobF?[0] else {return}
        M4LoanResultLogo.sd_setImage(with: URL(string: order.UcddgfwSXM ?? ""))
        M4LoanResultName.text = order.LcMnJMQqO
        M4LoanResultAmount.text = "$"+M4String.M4BlankAmount(original: "\(order.Nsrzn ?? 0)")
        M4LoanResultDays.text = "\(order.Xex ?? 0)Días"
        let status = order.VRFYc
        M4LoanResultSataus.textColor = COLOR_333333
        if status == 0 || status == 1 || status == 2 || status == 3 {
            M4LoanResultImage.image = UIImage(named: "product_pic_check")
            M4LoanResultSataus.text = "En revisión"
            M4LoanResultDescribe.text = "En 1 minuto como máximo, por favor espere un momento"
        }
        else if status == 4 {
            M4LoanResultImage.image = UIImage(named: "product_pic_pass")
            M4LoanResultSataus.text = "Aprobación de la revisión"
            M4LoanResultDescribe.text = "Proceso de desembolso en curso"
        }
        else if status == 6 {
            M4LoanResultImage.image = UIImage(named: "product_pic_failed")
            M4LoanResultSataus.text = "Revisión no aprobada"
            M4LoanResultDescribe.text = "Puede volver a solicitar después de \(order.zxcoePS ?? 0) días"
        }
        else if status == 7 {
            M4LoanResultImage.image = UIImage(named: "product_pic_transfe_failed")
            M4LoanResultSataus.text = "Fallo de transferencia"
            M4LoanResultDescribe.text = "La transferencia del pedido actual ha fallado,póngase en contacto con el servicio de atención al cliente para procesarla"
            M4LoanResultSataus.textColor = COLOR_9D0000
//            M4CellActionDelegate?.M4CellAction(M4IDAction(actionType: M4LoanResultAction.M4ResultReturnHome.rawValue))
        }
    }
    
    override func M4SecondDataRefresh() {
        let count = data2 as? Int
        M4LoanResultLabel.isHidden = count == 0 ? true : false
    }
    
    @IBAction func M4LoanPrivacyButtonClick(_ sender: UIButton) {
        M4CellActionDelegate?.M4CellAction(M4IDAction(actionType: M4LoanResultAction.M4ResultPrivacyAction.rawValue))
        sender.M4EventUnavailable = false
    }
    
    @IBAction func M4LoanToHomeClick(_ sender: UIButton) {
        AppDelegate.keyWindow()?.rootViewController = M4TabBarViewController()
        sender.M4EventUnavailable = false
    }
    
    
    
}
